<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<view class="back iconfont icon-xiangzuo1" @tap="backPage"></view>
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">生成优惠券</view>
		</view>
		
		<view class="clear_box"></view>
		
		<view class="details_box">
			<view class="list">
				<view class="name">券数量</view>
				<input type="number" v-model="stock" value="" placeholder="请输入优惠券数量" />
			</view>
			<view class="list">
				<view class="name">券价格</view>
				<input type="number" v-model="money" value="" placeholder="请输入优惠券价格" />
			</view>
			<view class="list">
				<view class="name">券标题</view>
				<!-- <input type="text" value="" placeholder="例：新用户专属" /> -->
				<picker class="sec" mode="selector" :range="sheet_list" @change="onChange">
				    <view class="picker">
				        {{name}}
				    </view>
				</picker>
				
			</view>
			<!-- <view class="list">
				<view class="name">有效时间</view>
				<input type="text" value="" placeholder="请输入有效时间" />
			</view> -->
			
			
		</view>
		<view class="clear_box04"></view>
		
		<view class="confirm" @click="commit()">确认生成</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				scrrol:false,
				info:'',
				sheet_list:[],
				name: '请选择',
				stock:'',
				money:'',
			}
		},
		onLoad() {
			let that = this;
			that.getTitle();
		},
		methods: {
			commit() {
				let that = this;
				if (!that.stock || !that.money || that.name=='请选择'){
					that.Msg.Fail('请填写内容');
					return;
				}
				that.Net._post('auth/coupon/add', {name:that.name,stock:that.stock,money:that.money}, res => {
					if (res.code == 200) {
						uni.setStorageSync('coupon_list', 1);
						that.Msg.Success('创建成功', res => {
							uni.navigateBack({});
						});
					}
				});
			},
			getTitle(){
				let that = this;
				that.Net._get('auth/coupon/title', {}, res => {
					if (res.code == 200) {
						that.sheet_list = res.data;
					}
				});
			},
			onChange(e) {
			    this.name = this.sheet_list[e.detail.value];
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},

		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		
	}
</script>

<style>
	
	.scrrolHeader{
		background-color: #FF7701 !important;
	}
	
	.details_box {
		width: 92%;
		margin: 4% auto 0;
		background-color: #fff;
		padding: 0vw 4%;
		border-radius: 3vw;
	}
	
	.details_boxNo{
		padding: 0vw 4%;
	}
	
	.details_box .details_title {
		font-size: 4.2vw;
		color: #333;
		font-weight: bold;
		margin-bottom: 5vw;
	}
	
	.details_box .input_box{
		width: 100%;
		display: flex;
		align-items: center;
		border-bottom: 2px solid #FC5D20;
		height: 15vw;
	}
	
	.details_box .input_box .m{
		font-size: 4vw;
		color: #333;
		margin-right: 1vw;
		font-weight: bold;
		margin-top: 2vw;
	}
	
	.details_box .input_box input{
		font-size: 7vw;
		color: #333;
		flex: 1;
		font-weight: bold;
	}
	
	.details_box .list {
		width: 100%;
		padding: 5vw 0;
		border-bottom: 1px solid #F3F3F3;
		display: flex;
		align-items: center;
		position: relative;
	}
	
	.details_box .list .name {
		font-size: 4.2vw;
		font-weight: bold;
		color: #333;
		margin-right: 4vw;
	}
	
	.details_box .list .text {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		margin-right: 1vw;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	
	.details_box .list .text .i{
		width: 5vw;
		margin-right: 1vw;
	}
	
	.details_box .list .text .i image{
		width: 100%;
	}
	
	.details_box .list input {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
		margin-right: 3vw;
		text-align: right;
		font-weight: bold;
	}
	
	.details_box .list .arrow {
		font-size: 3.5vw;
		color: #333;
	}
	
	.details_box .list .yzm {
		font-size: 3.5vw;
		color: #FC5D20;
		font-weight: bold;
		outline: none;
		background-color: transparent !important;
		border-radius: 10vw;
		height: 10vw;
		border: 1px solid #FC5D20;
	}
	
	.sec{
		float: right;
		flex: 1;
		font-size: 3.5vw;
		color: #333 !important;
		margin-right: 3vw;
		text-align: right;
		font-weight: bold;
	}
	
	.picker{
		color: #333 !important;
	}
	
</style>
